package com.ky.facescan.api.rx.subscriber;

import android.content.Context;
import android.content.Intent;

import com.ky.facescan.api.exception.BaseException;
import com.ky.facescan.base.mvp.BaseView;
import com.ky.facescan.utils.LogUtils;


public abstract class ProgressSubscriber<T> extends ErrorHandlerSubscriber<T> {

    private BaseView mView;

    public ProgressSubscriber(Context context, BaseView view) {
        super(context);
        this.mView = view;

    }

    public boolean isShowProgress() {
        return true;
    }

    @Override
    public void onStart() {
        if (isShowProgress()) {
            mView.showLoading();
        }
    }

    @Override
    public void onCompleted() {
        mView.hideLoading();
    }


    @Override
    public void onError(Throwable e) {
        e.printStackTrace();
        BaseException baseException = mRxErrorHandler.handleError(e);
        mView.showError(baseException.getDisplayMessage());
        //token失效
        if (BaseException.ERROR_TOKEN.equals(baseException.getCode())) {
            LogUtils.e("ProgressSubscriber   token失效");
            toLogin();
        }
    }

    private void toLogin() {
//        Intent intent = new Intent(mActivity, LoginActivity.class);
//        mActivity.startActivity(intent);
    }


}
